#!/bin/sh
# 安装、更新PCRE库
App=pcre
AppName="PCRE库"
AppDir=/usr/local
AppSrcBase=/App/src
AppSrcFile=$App-*.tar.*
AppSrcDir=$(find $AppSrcBase -maxdepth 1 -name "$AppSrcFile" -type f | sed -e 's/.tar.*$//')

# 安装
finstall()
{
    test -f $AppDir/lib/libpcre.so && echo "$AppName已安装" || fupdate
}

# 更新
fupdate() 
{
    cd $AppSrcBase
    test -d $AppSrcDir && rm -rf $AppSrcDir
    find $AppDir/share/man/man3/ -name "pcre*" -exec rm -f {} \;

    tar jxf $AppSrcFile || tar zxf $AppSrcFile
    cd $AppSrcDir
    ./configure --prefix=$AppDir && make && make install
    [ $? -eq 0 ] && echo "$AppName安装成功" || echo "$AppName安装失败"

    grep -q "$AppDir/lib" /etc/ld.so.conf.d/app.conf || echo "$AppDir/lib" >> /etc/ld.so.conf.d/app.conf
}

ScriptFile=$(basename $0)
case "$1" in
    "install") finstall;;
    "update" ) fupdate;;
    * )
    echo "用法：$ScriptFile {install|update}"
    ;;
esac
